package ownBuyTicket;

public class Buy implements Runnable{
    static int num = 1000;
    @Override
    public void run() {
        while (true){
            synchronized (Buy.class){
            if(num == 0){
                break;
            }else {
                System.out.println(Thread.currentThread().getName() + "买了第" + num +"张票");
                num--;
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            }
        }
    }
}
